//
//  FriendsInformViewController.m
//  觅影
//
//  Created by  陶虹 on 16/4/9.
//  Copyright © 2016年  陶虹. All rights reserved.
//

#import "FriendsInformViewController.h"
#import "FriendsInformCell.h"
#import "FriendsInformModel.h"

@interface FriendsInformViewController ()<UITableViewDataSource, UITableViewDelegate, FriendsInformCellDelegate>
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *modelArray;
@property (nonatomic, strong) NSString *myUsername;

@end

@implementation FriendsInformViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"FriendsInformCell" bundle:nil] forCellReuseIdentifier:@"friendsInformCell"];
    
}
// 懒加载
- (NSMutableArray *)modelArray{
    if (!_modelArray) {
        _modelArray = [NSMutableArray array];
    }
    return _modelArray;
}

// 环信代理方法，接收到好友请求
- (void)didReceiveBuddyRequest:(NSString *)username message:(NSString *)message{
    
    FriendsInformModel *model = [[FriendsInformModel alloc] init];
    model.username = username;
    [self.modelArray addObject:model];
}

#pragma mark --- tableView代理方法 ---
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.modelArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    FriendsInformCell *cell = [tableView dequeueReusableCellWithIdentifier:@"friendsInformCell" forIndexPath:indexPath];
    
    FriendsInformModel *model = self.modelArray[indexPath.row];
    cell.selectionStyle = UITableViewCellStyleDefault;
    cell.informLabel.text = [NSString stringWithFormat:@"%@请求加你为好友", model.username];
    
    cell.delegate = (id)self;
    cell.row = indexPath.row;
    return cell;
}

// 实现代理方法
- (void)removeCellWithRow:(NSInteger)row{
    FriendsInformModel *model = self.modelArray[row];
    [self.modelArray removeObject:model];
    [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
